WithNaN.hookOpCast

If rhs is WithNaN.defaultValue!Rhs, returns WithNaN.defaultValue!Lhs. Otherwise, returns cast(Lhs) rhs.

struct WithNaN
static
Lhs
hookOpCast
(
Lhs
Rhs
)
(
Rhs rhs
)

Parameters

rhs
Type: Rhs

the value being cast (Rhs is the first argument to Checked)

Lhs

the target type of the cast

Return Value

Type: Lhs

The result of the cast operation.

Examples

1 auto x = checked!WithNaN(422);
2 assert((cast(ubyte) x) == 255);
3 x = checked!WithNaN(-422);
4 assert((cast(byte) x) == -128);
5 assert(cast(short) x == -422);
6 assert(cast(bool) x);
7 x = x.init; // set back to NaN
8 assert(x != true);
9 assert(x != false);

Meta